﻿<script type="text/javascript">

function initCredentialsImg(canId) {
	$('#moduls_credentials_datagrid').datagrid({
		url : 'credentialsAction!query.action?canId=' + canId,
		fit : true,
		border : false,
		rownumbers : true,
		checkOnSelect : false,
		selectOnCheck : false,
		idField : 'creId',
		nowrap : false,
		columns : [ [ {
			title : '编号',
			field : 'creId',
			width : 150,
			checkbox : true
		}, {
			title : '证书图片',
			field : 'fileName',
			width : 110,
			formatter : function(value, row, index) {
				return '<img src="imgs/vote/credentials/' + value +'" width="100" height="120"></img>';
			}
		}, {
			field : 'action',
			title : '动作',
			width : 100,
			formatter : function(value, row, index) {
				if (row.id == '0') {
					return '系统角色';
				} else {
					return formatString('<img onclick="moduls_credentials_editFun(\'{0}\');" src="{1}"/>&nbsp;&nbsp;&nbsp;<img onclick="moduls_credentials_deleteFun(\'{2}\');" src="{3}"/>', row.creId, 'jslib/jquery-easyui-1.3.1/themes/icons/pencil.png', row.creId, 'jslib/jquery-easyui-1.3.1/themes/icons/cancel.png');
				}
			}
		} ] ],
		toolbar : [ {
			text : '增加',
			iconCls : 'icon-add',
			handler : function() {
				moduls_credentials_addFun();
			}
		}, '-', {
			text : '批量删除',
			iconCls : 'icon-remove',
			handler : function() {
				moduls_credentials_removeFun();
			}
		}, '-', {
			text : '刷新',
			iconCls : 'icon-reload',
			handler : function() {
				$('#moduls_credentials_datagrid').treegrid('reload');
			}
		} ]
	});
	
	$("#addCredentials_form input[name='canId']").val(canId);
}

var action_url = '';
function moduls_credentials_editFun(id) {
	$("#addCredentials_form input[name='imgs']").removeAttr('multiple');
	action_url = 'credentialsAction!modify.action';
	$("#addCredentials_form input[name='creId']").val(id);
	$('#addCredentials_form input[name=imgs]').trigger('click');
}
function moduls_credentials_addFun() {
	$("#addCredentials_form input[name='imgs']").attr('multiple', 'multiple');
	action_url = 'credentialsAction!add.action';
	$('#addCredentials_form input[name=imgs]').trigger('click');
}

function moduls_doCredentials_addFun() {
	$('#addCredentials_form').form('submit', {
		url : action_url,
		success : function(result) {
			var r = $.parseJSON(result);
			$.messager.show({
				title : '提示',
				msg : r.msg
			});
			if(r.success) {
				$('#moduls_credentials_datagrid').datagrid('load');
			}
		}
	});
}
function moduls_credentials_removeFun() {
	var rows = $('#moduls_credentials_datagrid').datagrid('getChecked');
	var ids = [];
	if (rows.length > 0) {
		$.messager.confirm('确认', '确定删除选中组及组下成员？', function(r) {
			if (r) {
				for ( var i = 0; i < rows.length; i++) {
					ids.push(rows[i].creId);
				}
				$.ajax({
					url : 'credentialsAction!delete.action',
					data : {
						ids : ids.join(',')
					},
					dataType : 'json',
					success : function(result) {
						if (result.success) {
							$('#moduls_credentials_datagrid').datagrid('load');
							$('#moduls_credentials_datagrid').datagrid('uncheckAll').datagrid('unselectAll').datagrid('clearSelections');
						}
						$.messager.show({
							title : '提示',
							msg : result.msg
						});
					}
				});
			}
		});
	} else {
		$.messager.show({
			title : '提示',
			msg : '请勾选要删除的记录！'
		});
	}
}
function moduls_credentials_deleteFun(id) {
	//console.info(id);
	$('#moduls_credentials_datagrid').datagrid('uncheckAll').datagrid('unselectAll').datagrid('clearSelections');
	var index = $('#moduls_credentials_datagrid').datagrid('getRowIndex', id);
	$('#moduls_credentials_datagrid').datagrid('checkRow', index);
	moduls_credentials_removeFun();
}
</script>
<form id="addCredentials_form" method="post" enctype="multipart/form-data">
<input type="hidden" name="creId" >
<input type="hidden" name="canId" >
<input type="file" style="display:none;" name="imgs" onchange="moduls_doCredentials_addFun()" />
</form>
<table id="moduls_credentials_datagrid"></table>